package org.realogic.cfm.util;

import java.text.DecimalFormat;
import java.text.NumberFormat;


public final class UtilMoney1 {
	private static String ls_number[] = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };

	private static String ls_flag[] = { "仟", "佰", "拾", "亿", "仟", "佰", "拾", "万", "仟", "佰", "拾", "元", "角", "分" };

	private UtilMoney1() {
	}

	public static String toChina(double aje) {
		String ls_money = "";
		String ls_chinese = "";
		if (aje < 0.001) {
			return "零元整";
		}
		DecimalFormat df = (DecimalFormat) NumberFormat.getInstance();
		df.applyPattern("#.00");
		ls_money = df.format(aje);
		ls_money = UtilString.replace(ls_money, ".", "");

		int li_len = ls_money.length();
		int offsize = 14 - li_len;
		if (li_len > 14 || li_len == 0) {
			return "";
		} else {
			for (int i = 0; i < li_len; i++) {
				int x = Integer.parseInt(ls_money.substring(i, i + 1));
				ls_chinese = ls_chinese + ls_number[x] + ls_flag[offsize + i];
			}
			ls_chinese = UtilString.replace(ls_chinese, "零仟", "零");
			ls_chinese = UtilString.replace(ls_chinese, "零零", "零");
			ls_chinese = UtilString.replace(ls_chinese, "零佰", "零");
			ls_chinese = UtilString.replace(ls_chinese, "零零", "零");
			ls_chinese = UtilString.replace(ls_chinese, "零拾", "零");
			ls_chinese = UtilString.replace(ls_chinese, "零零", "零");
			ls_chinese = UtilString.replace(ls_chinese, "零亿", "亿");
			ls_chinese = UtilString.replace(ls_chinese, "零万", "万");
			ls_chinese = UtilString.replace(ls_chinese, "亿万", "亿零");
			ls_chinese = UtilString.replace(ls_chinese, "零零", "零");
			ls_chinese = UtilString.replace(ls_chinese, "零元", "元");
			if (ls_chinese.indexOf("零角") > -1) {
				ls_chinese = UtilString.replace(ls_chinese, "零角", "零");
			}
			ls_chinese = UtilString.replace(ls_chinese, "零零", "零");
			if (ls_chinese.indexOf("零分") > -1) {
				ls_chinese = UtilString.replace(ls_chinese, "零分", "整");
			}
			return ls_chinese;
		}
	}
}
